﻿#region Declaration

//------------------------------------------------------------------------------
// Compas Information Techonoly Co., Ltd
// The Initial Developer of the Original Code is CompasSolutions.
// All Rights Reserved.
// 
// Contributor(s): _______. 
//------------------------------------------------------------------------------

#endregion

#region Using Directives

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

#endregion

namespace QuickDev.Common.ApplicationSettings
{
    [Serializable()]
    public class AppSettings
    {
        #region Constants

        public const string SECTION_NAME = "siteSettings";

        #endregion

        #region Member Variables

        private bool _useCaching = false;
        private int _shortCacheSeconds = 120;  //2 minutes
        private int _normalCacheSeconds = 300; //5 minutes
        private int _longCacheSeconds = 1500;  // 25 minutes

        #endregion

        #region .Ctors

        /// <summary>
        /// .Ctors
        /// </summary>
        public AppSettings()
        {
            _useCaching = false;
            Boolean.TryParse( Configurations.Instance["UseCaching"].ToString() , out _useCaching );

            _shortCacheSeconds = 120;
            Int32.TryParse( Configurations.Instance["ShortCacheSeconds"].ToString() , out _shortCacheSeconds );

            _normalCacheSeconds = 300;
            Int32.TryParse( Configurations.Instance["NormalCacheSeconds"].ToString() , out _normalCacheSeconds );

            _longCacheSeconds = 9000;
            Int32.TryParse( Configurations.Instance["LongCacheSeconds"].ToString() , out _longCacheSeconds );
        }

        #endregion

        #region Methods

        #region Public

        /// <summary>
        /// Loads this instance.
        /// </summary>
        /// <returns></returns>
        public static AppSettings Load()
        {
            return new AppSettings();
        }

        #endregion

        #endregion

        #region Properties

        /// <summary>
        /// Gets or sets a value indicating whether the site should use caching.
        /// </summary>
        /// <value><c>true</c> if [use caching]; otherwise, <c>false</c>.</value>
        public bool UseCaching
        {
            get
            {
                return _useCaching;
            }
            set
            {
                _useCaching = value;
            }
        }

        /// <summary>
        /// Gets or sets the short cache seconds.
        /// </summary>
        /// <value>The short cache seconds.</value>
        public int ShortCacheSeconds
        {
            get
            {
                return _shortCacheSeconds;
            }
            set
            {
                _shortCacheSeconds = value;
            }
        }

        /// <summary>
        /// Gets or sets the normal cache seconds.
        /// </summary>
        /// <value>The normal cache seconds.</value>
        public int NormalCacheSeconds
        {
            get
            {
                return _normalCacheSeconds;
            }
            set
            {
                _normalCacheSeconds = value;
            }
        }

        /// <summary>
        /// Gets or sets the long cache seconds.
        /// </summary>
        /// <value>The long cache seconds.</value>
        public int LongCacheSeconds
        {
            get
            {
                return _longCacheSeconds;
            }
            set
            {
                _longCacheSeconds = value;
            }
        }

        #endregion
    }
}
